
		<table id="<?php echo $reportdef['id']?>" class="flexiMe" style="display:none"><tr><td></td></tr></table>
		<?php 
		$f = 0;
		foreach($reportdef['fields'] as $field):
			$f++;
		endforeach;
		?>
		<script type="text/javascript">
		function refresh<?php echo $reportdef['id']?>(){
			//debugger;
			$("#<?php echo $reportdef['id']?>").flexigrid
			(
			{
			url: "<?php print url_for('reports/getData?id='. $reportdef['id']); ?>",
			dataType: 'json',
			colModel : [
					<?php 
					$i = 0;
					if($reportdef['showActions']){
						echo "{display: '".__('Actions')."', name : 'actions', width: 50,  sortable : false, align: 'center'}, \n";
					}
					foreach($reportdef['fields'] as $field):
						$i++;
						$name = $field->getAttribute('name');
						$type = $field->getElementsByTagName('type')->item($k)->nodeValue;
						$label = $field->getElementsByTagName('label')->item($k)->nodeValue;
						$width = $field->getElementsByTagName('width')->item($k)->nodeValue;
						$sortable = $field->getElementsByTagName('sortable')->item($k)->nodeValue;
						$align = $field->getElementsByTagName('align')->item($k)->nodeValue;
						if($field->getElementsByTagName('searchable')->item($k)->nodeValue=='true'){
							$searchFields[$name] = $label;
						}
						if($i==$f){
							$fin = '';
						}else{
							$fin = ',';
						}
						echo "{display: '".html_entity_decode(htmlentities($label, ENT_QUOTES))."', name : '$name', width: $width,  sortable : $sortable, align: '$align'}$fin \n";
					endforeach;
					?>
				],
			buttons : [{name: "<?php echo __('Export')?>", bclass: 'flexiGrid_export', onpress : exporter<?php echo $reportdef['id']?>}],
			<?php if(count($searchFields)>0):?>
			searchitems : [
			   	<?php
			   		$i = 0; 
			   		foreach($searchFields as $name => $label){
			   		$i++;
			   		if($i==$f){
						$fin = '';
					}else{
						$fin = ',';
					}
					echo "{display: '".html_entity_decode(htmlentities($label, ENT_QUOTES))."', name : '$name'}$fin\n";
			   		}?>		
				],
			<?php endif;?>		
			sortname: "<?php echo $reportdef['sortField']?>",
			sortorder: "<?php echo $reportdef['sortOrder']?>",
			usepager: true,
			title: "<?php echo $reportdef['title'];?>",
			useRp: true,
			rp: 15,
			nowrap: false,
			showTableToggleBtn: true,
			width: 'auto',
			onSubmit: addFormData<?php echo $reportdef['id']?>,
			height:'auto',
			pagestat: "<?php echo __('Displaying {from} to {to} of {total} items')?>",
			pagetext: "<?php echo __('Page')?>",
			outof: "<?php echo __('of')?>",
			findtext: "<?php echo __('Find')?>",
			procmsg: "<?php echo __('Processing, please wait ...')?>"
			}
			);
			$('#<?php echo $reportdef['id']?>').flexOptions({newp: 1}).flexReload();
		 }
		
		//This function adds paramaters to the post of flexigrid. You can add a verification as well by return to false if you don't want flexigrid to submit			
		function addFormData<?php echo $reportdef['id']?>()
			{
			
			//passing a form object to serializeArray will get the valid data from all the objects, but, 
			//if the you pass a non-form object, you have to specify the input elements that the data will come from
			//var dt = $('#paramsForm').serializeArray(); //cette fonction ne marchait pas avec IE!
			var $inputs = $('#paramsForm :input'); 
			//var $inputs = $(':input');
			var values = new Array() ; 
		    for(var i= 0; i < $inputs.length; i++)
		    {
		    	thisInput = $inputs[i];
		    	var value = {};
		    	value['name'] = $inputs[i].name;
		    	if($inputs[i].type == 'checkbox'){
		    		value['value'] = $inputs[i].checked;
		    	}else if($inputs[i].type == 'select-multiple'){
		    		options = new Array();
		    		for(var j= 0; j < $inputs[i].options.length; j++){
						if($inputs[i].options[j].selected){
							options.push($inputs[i].options[j].value);
						}
		    		}
		    		value['value'] = array2json(options);
		    	}else{
		    		value['value'] = $inputs[i].value;
		    	}
		        values[i] = value; 
		    };
		    
			$("#<?php echo $reportdef['id']?>").flexOptions({params: values});

			//Bug que je n'ai pas eu le temps de corriger.
			if($('input.qsbox').first().length>0){
				this.query = $('input.qsbox').first()[0].value;
			}
			
			
			return true;
			}
			
		$('#paramsForm').submit
		(
			function ()
				{
					$('#<?php echo $reportdef['id']?>').flexOptions({newp: 1}).flexReload();
					return false;
				}
		);						
		
		function exporter<?php echo $reportdef['id']?>(){
		
			//I send all imputs to send also the search values! 
			var $inputs = $(':input');
			var query = '<?php print url_for('reports/exportData?id='.$reportdef['id']); ?>'; 
			var first = true;
		    for(var i= 0; i < $inputs.length; i++)
		    {
		        if(first){
		            var symbol = '?';
		        }else{
		        	var symbol = '&';
		        }
		        first = false;
		        if($inputs[i].name!=''){
		        	switch ($inputs[i].type) {
		        		case "checkbox":
			            var inputValue = $inputs[i].checked;
			        break;
		        		case "select-multiple":
			    		options = new Array();
			    		for(var j= 0; j < $inputs[i].options.length; j++){
							if($inputs[i].options[j].selected){
								options.push($inputs[i].options[j].value);
							}
			    		}
			    		var inputValue = array2json(options);
		        	break;
		        		default: 
					    var inputValue = $inputs[i].value;
				    }
			        
		    		query = query+symbol+$inputs[i].name+'='+inputValue;
		        }
		    };
			
			var elemIF = document.createElement("iframe");
			elemIF.src = query; 
			elemIF.id = 'upload_target'; 
			elemIF.style.display = "none"; 
			document.body.appendChild(elemIF);
		
		}
</script>
